From c31ae98f3e2ff3e9f4da04a7d3a9dd2a7ebe2685 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Mon, 29 Jul 2024 11:28:22 -0500 Subject: [PATCH] Abstract template table rows --- src/pgwui_common/templates/auth_base.mak | 206 +++++++++++++---------- 1 file changed, 120 insertions(+), 86 deletions(-) diff --git a/src/pgwui_common/templates/auth_base.mak b/src/pgwui_common/templates/auth_base.mak index 133ab3c..e4d2d12 100644 --- a/src/pgwui_common/templates/auth_base.mak +++ b/src/pgwui_common/templates/auth_base.mak @@ -54,10 +54,18 @@ <%! from pgwui_common.path import asset_abspath + import attrs errors_base_mak = asset_abspath('pgwui_common:templates/errors_base.mak') auth_parts_mak = asset_abspath('pgwui_common:templates/auth_parts.mak') lib_mak = asset_abspath('pgwui_common:templates/lib.mak') + + @attrs.define + class TabIndex(): + val = attrs.field(default=1) + + def inc(self, amount=1): + self.val += amount %> <%inherit file="${errors_base_mak}" /> @@ -74,6 +82,107 @@ +<%doc> All the *_row() defs take a tab_index and, as a side effect, + increment the tab_index with the number of rows added to the + table. + + +<%def name="database_row(tab_index)"> + + + + + + + + + <% tab_index.inc() %> + + +<%def name="format_row(tab_index)"> + + Uploaded Data Format: + + + +
+ + + + + <% tab_index.inc(2) %> + + +<%def name="nulls_row(tab_index)"> + % if upload_nulls: + + + + + + + + + + + + + + + + + <% tab_index.inc(2) %> + % endif + + +<%def name="file_row(tab_index)"> + + + + + + + + + <% tab_index.inc() %> + + <%def name="upload_form(extra_rows=[], upload_nulls=True)">
@@ -86,102 +195,27 @@ % endif
+ <% tab_index = TabIndex() %> - - - - - ${self.auth_parts.user_row(2, havecreds, user)} - <% tab_index = 3 %> - ${self.auth_parts.password_row(tab_index, havecreds)} + ${database_row(tab_index)} + ${self.auth_parts.user_row(tab_index.val + 1, havecreds, user)} + ${self.auth_parts.password_row(tab_index.val + 2, havecreds)} + <% tab_index.inc(2) %> % for row in extra_rows: <% - tab_index += 1 + tab_index.inc() %> - ${row(tab_index) | n} + ${row(tab_index.val) | n} % endfor - - - - - % if upload_nulls: - - - - - - - - - % endif - - - - + ${format_row(tab_index)} + ${nulls_row(tab_index)} + ${file_row(tab_index)}
- - - -
Uploaded Data Format: - - -
- - -
- - - -
- - - -
- - - -

- +

-- 2.34.1